package com.dingwen.treasure.business.service.impl;

import com.dingwen.treasure.base.constant.PayConstant;
import com.dingwen.treasure.base.pojo.vo.ResultGenerator;
import com.dingwen.treasure.business.model.dto.PayDto;
import com.dingwen.treasure.business.service.AbstractPayServiceImplementsForFunction;
import com.dingwen.treasure.business.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.function.Supplier;

/**
 * 微信支付: 抽象类基于函数式接口实现
 *
 * @author dingwen
 * @date 2022/04/25
 */
@SuppressWarnings("ALL")
@Service(value = PayConstant.WX_PAY)
@Slf4j
public class WXPayServiceImpl extends AbstractPayServiceImplementsForFunction implements PayService {
    /**
     * 支付
     */
    @Override
    public void pay() {

        PayDto payDTO = PayDto.builder().build();

        // 需要自己实现自定义的方法 set 到 payDTO 中

        // 执行支付
        execute(payDTO);

        log.info("wx pay...");
    }

    /**
     * 获取支付的类型
     *
     * @return {@link String}
     */
    @Override
    public String getPayType() {
        return PayConstant.WX_PAY;
    }

    /**
     * 获取调用请求方法
     *
     * @return {@link Supplier}<{@link String}>
     */
    @Override
    protected Supplier<String> getInvokeRequestMethod() {
        return () -> {
            log.info("执行请求...");
            return ResultGenerator.genSuccessResult().toString();
        };
    }
}
